/**
 * QuestionListController.java
 * Version 1.0.0
 * Created on 2018年8月25日
 *
 */
package com.yincheng.oes.business.base.question;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yincheng.oes.business.util.Tools;
import com.yincheng.oes.business.util.dictionary.DictionaryService;

/**
 * @author yangsy
 * @version 1.0.0
 * @since
 * 创建时间：2018年8月25日
 * <p>
 * 功能描述：问题详情列表controller
 * <p>
 * 邮箱地址：446948434@qq.com
 */
@Controller
@RequestMapping("/questionList")
public class QuestionListController {

    @Autowired
    private QuestionListService questionListService;

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 题目查询列表页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/listPage.html", method = RequestMethod.GET)
    public String listPage(Model model) {
        setView(model);
        return "business/question/questionlist";
    }

    @RequestMapping(value = "/getList.json", method = RequestMethod.GET)
    @ResponseBody
    public String list(QueryParamBean bean) {
        Pair<Integer, List<QueryResultRowBean>> pair = questionListService.getQuestionListByParam(bean);
        return Tools.toEasyuiDataGrid(pair.getLeft(), pair.getRight());
    }

    /**
     * 创建试卷题目检索列表页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/listSearchPage.html", method = RequestMethod.GET)
    public String listSearchPage(Model model) {
        setView(model);
        return "business/paper/questionlist";
    }

    /**
     * 学生疑问关联题目检索页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/listAskPage.html", method = RequestMethod.GET)
    public String listAskPage(Model model) {
        setView(model);
        return "business/question/questionlist-ask";
    }

    /**
     * @param model
     */
    private void setView(Model model) {
        model.addAttribute("quesTypes", dictionaryService.getByModel("ques_type"));
        model.addAttribute("quesSources", dictionaryService.getByModel("ques_source"));
    }
}
